package com.jy.appmarket.screenlock.model;

import android.os.Parcel;
import android.os.Parcelable;

public class FileDownloadModel implements Parcelable, Comparable<FileDownloadModel> {

	public static final String FAVOR = "favor";
	public static final String SW_RECOMMEND = "sw_rec";
	public static final String GAME_RECOMMEND = "game_rec";
	public static final String PHONE_ESSENTIAL = "phone_essential";
	public static final String HOTTEST_APP = "hottest_app";
	public static final String SEARCH = "search";
	public static final String TOOL_WIDGET = "tool_widget";
	public static final String GAME_WIDGET = "game_widget";
	public static final String ENTERTAINMENT_WIDGET = "entertainment_widget";
	public static final String HIDDEN = "hidden";
	public static final String PUSH_APP = "push_app";
	public static final String TOPIC = "topic";
	public static final String WEB_VIEW ="web_view";
	/**
	 * 分类名称的构成
	 * 
	 * @param category
	 *            软件为sw,游戏为game
	 * @param id
	 *            分类id
	 */
	public static String createCategoryId(String category, String id) {

		return category + "_" + id;
	}

	private String id;
	private String appName;
	private String iconUrl;
	private String dlUrl;
	private String createTime;
	private String lastModifyTime;
	private int hidden;
	private String pkgName;
	private long totalSize;
	private int needtrim;
	private String source = "";
	private int status;

	private int autoInstall = 1;

	private long downloadedSize;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getAppName() {
		return appName;
	}

	public void setAppName(String appName) {
		this.appName = appName;
	}

	public String getIconUrl() {
		return iconUrl;
	}

	public void setIconUrl(String iconUrl) {
		this.iconUrl = iconUrl;
	}

	public String getDlUrl() {
		return dlUrl;
	}
	public void setDlUrl(String dlUrl) {
		this.dlUrl = dlUrl;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getLastModifyTime() {
		return lastModifyTime;
	}

	public void setLastModifyTime(String lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}

	public int getHidden() {
		return hidden;
	}

	public void setHidden(int hidden) {
		this.hidden = hidden;
	}

	public String getPkgName() {
		return pkgName;
	}

	public void setPkgName(String pkgName) {
		this.pkgName = pkgName;
	}

	public long getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(long totalSize) {
		this.totalSize = totalSize;
	}

	public int getNeedtrim() {
		return needtrim;
	}

	public void setNeedtrim(int needtrim) {
		this.needtrim = needtrim;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public void setDownloadedSize(long size) {
		this.downloadedSize = size;
	}

	public long getDownloadedSize() {
		return this.downloadedSize;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public int getAutoInstall() {
		return autoInstall;
	}

	public void setAutoInstall(int autoInstall) {
		this.autoInstall = autoInstall;
	}

	public void modifyValues(FileDownloadModel fdm) {
		id = fdm.id;
		appName = fdm.appName;
		iconUrl = fdm.iconUrl;
		dlUrl = fdm.dlUrl;
		createTime = fdm.createTime;
		lastModifyTime = fdm.lastModifyTime;
		hidden = fdm.hidden;
		pkgName = fdm.pkgName;
		totalSize = fdm.totalSize;
		needtrim = fdm.needtrim;
		source = fdm.source;
		status = fdm.status;
		// downloadedSize;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(id);
		dest.writeString(appName);
		dest.writeString(iconUrl);
		dest.writeString(dlUrl);
		dest.writeString(createTime);
		dest.writeString(lastModifyTime);
		dest.writeInt(hidden);
		dest.writeString(pkgName);
		dest.writeLong(totalSize);
		dest.writeInt(needtrim);
		dest.writeString(source);
		dest.writeInt(status);
		dest.writeInt(autoInstall);
		dest.writeLong(downloadedSize);
	}

	public static final Parcelable.Creator<FileDownloadModel> CREATOR = new Parcelable.Creator<FileDownloadModel>() {
		@Override
		public FileDownloadModel createFromParcel(Parcel source) {
			FileDownloadModel fdm = new FileDownloadModel();
			fdm.setId(source.readString());
			fdm.setAppName(source.readString());
			fdm.setIconUrl(source.readString());
			fdm.setDlUrl(source.readString());
			fdm.setCreateTime(source.readString());
			fdm.setLastModifyTime(source.readString());
			fdm.setHidden(source.readInt());
			fdm.setPkgName(source.readString());
			fdm.setTotalSize(source.readLong());
			fdm.setNeedtrim(source.readInt());
			fdm.setSource(source.readString());
			fdm.setStatus(source.readInt());
			fdm.setAutoInstall(source.readInt());
			fdm.setDownloadedSize(source.readLong());
			return fdm;
		}

		@Override
		public FileDownloadModel[] newArray(int size) {
			return new FileDownloadModel[size];
		}
	};

	@Override
	public String toString() {
		return "FileDownloadModel [id=" + id + ", appName=" + appName + ", iconUrl=" + iconUrl + ", dlUrl=" + dlUrl
				+ ", createTime=" + createTime + ", lastModifyTime=" + lastModifyTime + ", hidden=" + hidden
				+ ", pkgName=" + pkgName + ", totalSize=" + totalSize + ", needtrim=" + needtrim + ", source=" + source
				+ ", status=" + status + ", autoInstall=" + autoInstall + ", downloadedSize=" + downloadedSize + "]";
	}

	@Override
	public int compareTo(FileDownloadModel another) {
		if (hidden != another.getHidden()) {
			return another.getHidden() - hidden;
		} else {
			return getStatusPriority(status) - getStatusPriority(another.getStatus());
		}
	}

	private int getStatusPriority(int status) {
//		if (status == FileDownloadService.STATUS_PENDING) {
//			return 3;
//		} else if (status == FileDownloadService.STATUS_PAUSED_BY_MOBILE_NETWORK) {
//			return 2;
//		} else if (status == FileDownloadService.STATUS_ERROR_DOWNLOAD) {
//			return 1;
//		} else {
//			return 0;
//		}
		return 0;
	}
}
